<template>
  <div class="orderList">
    <el-card class="searchBar" shadow="never">
      <div class="searchBar-title">查询条件</div>
      <el-form
        ref="form"
        :inline="true"
        :model="searchForm"
        class="demo-form-inline"
        size="small"
      >
        <el-form-item label="订单编号">
          <el-input v-model="searchForm.orderSn" placeholder="请填写订单编号" />
        </el-form-item>
        <el-form-item label="订单类型">
          <el-select
            v-model="searchForm.orderType"
            clearable
            placeholder="订单类型"
          >
            <el-option label="正常订单" value="0" />
            <el-option label="秒杀订单" value="1" />
          </el-select>
        </el-form-item>
        <el-form-item label="支付方式">
          <el-select
            v-model="searchForm.payType"
            clearable
            placeholder="支付方式"
          >
            <el-option label="未支付" value="0" />
            <el-option label="支付宝" value="1" />
            <el-option label="微信" value="2" />
          </el-select>
        </el-form-item>
        <el-form-item label="订单状态">
          <el-select
            v-model="searchForm.status"
            clearable
            placeholder="支付方式"
          >
            <el-option label="待付款" value="0" />
            <el-option label="待发货" value="1" />
            <el-option label="已发货" value="2" />
            <el-option label="已完成" value="3" />
            <el-option label="已关闭" value="4" />
            <el-option label="无效订单" value="5" />
          </el-select>
        </el-form-item>
        <div class="searchBar-btn">
          <el-form-item>
            <el-button size="mini" type="primary" @click="onSearch"
              >查询</el-button
            >
          </el-form-item>
          <el-form-item>
            <el-button size="mini" @click="onReset">重置</el-button>
          </el-form-item>
        </div>
      </el-form>
    </el-card>
    <el-card class="formTable">
      <el-table :data="tableData" style="width: 100%" border>
        <el-card>
          <el-card class="main-header" shadow="never" />
          <el-table-column label="#" fixed type="index" align="center" />
          <el-table-column
            label="订单序号"
            width="300px"
            prop="orderSn"
            align="center"
          />
          <el-table-column label="支付方式" align="center" width="120px">
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.payType == 1"
                size="mini"
                type="primary"
                class="payBtn"
              >
                <svg-icon aria-hidden="true" icon-class="payicon" />
              </el-button>
              <el-button
                v-else-if="scope.row.payType == 2"
                size="mini"
                type="success"
                class="payBtn"
              >
                <svg-icon aria-hidden="true" icon-class="weixin" />
              </el-button>
              <el-button v-else size="mini" type="info" class="noPay" plain>
                未支付
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="订单状态" align="center" width="150px">
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.status == 0"
                type="danger"
                size="small"
              >
                待付款
              </el-button>
              <el-button
                v-else-if="scope.row.status == 1"
                type="warning"
                size="small"
              >
                待发货
              </el-button>
              <el-button
                v-else-if="scope.row.status == 2"
                type="primary"
                plain
                size="small"
              >
                已发货
              </el-button>
              <el-button
                v-else-if="scope.row.status == 3"
                type="success"
                size="small"
              >
                已完成
              </el-button>
              <el-button
                v-else-if="scope.row.status == 4"
                type="info"
                size="small"
              >
                已关闭
              </el-button>
              <el-button
                v-else-if="scope.row.status == 5"
                type="danger"
                size="small"
              >
                无效订单
              </el-button>
            </template>
          </el-table-column>
          <el-table-column
            label="添加时间"
            prop="createTime"
            align="center"
            width="200px"
          />
          <el-table-column
            label="下单时间"
            prop=""
            align="center"
            width="200px"
          >
            <template slot-scope="scope">
              <div>
                <div v-if="scope.row.paymentTime">
                  {{ scope.row.paymentTime }}
                </div>
                <div v-else style="color: #f00">未支付</div>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="用户账号"
            prop="memberUsername"
            align="center"
            width="180px"
          />
          <el-table-column label="订单类型" align="center" width="130px">
            <template slot-scope="scope">
              <div>
                <el-button size="mini" plain type="success">{{
                  scope.row.orderType !== 0 ? '正常订单' : '秒杀订单'
                }}</el-button>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="备注"
            prop="note"
            align="center"
            width="200px"
          />
          <el-table-column
            fixed="right"
            label="操作"
            align="center"
            width="200px"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="primary"
                icon=" el-icon-view"
                @click="handleEdit(scope.row.id)"
                >查看订单</el-button
              >
            </template>
          </el-table-column>
        </el-card>
      </el-table>
      <!-- 分页 -->
      <div class="main-footer">
        <el-pagination
          :current-page="page.currentPage"
          :page-sizes="page.pageSizes"
          :page-size="page.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>
  </div>
</template>

<script>
import { findOrdersByPage } from '@/api/orders/orderList/index'
import mixins from '@/mixins/index'
export default {
  mixins: [mixins],
  data() {
    return {
      searchForm: {},
      tableData: []
    }
  },
  created() {
    this.init()
  },
  mounted() {},
  methods: {
    init() {
      findOrdersByPage(
        this.page.currentPage,
        this.page.pageSize,
        this.searchForm
      ).then((res) => {
        this.tableData = res.data.rows
        this.page.total = res.data.total
      })
    },
    // 搜索
    onSearch() {
      // productList
      this.page.currentPage = 1
      this.init()
    },
    // 重置搜索框
    onReset() {
      this.searchForm = this.$options.data().searchForm
      this.onSearch()
    },
    // 查看订单详情
    handleEdit(id) {
      this.$router.push({ path: `orderDetail/${id}` })
    }
  }
}
</script>

<style lang="scss" scoped>
.orderList {
  .searchBar {
    .demo-form-inline {
      margin: 20px 20px 0;
      flex-wrap: wrap;
      .el-form-item {
        margin: 10px 20px 0;
      }
    }
  }
  .formTable {
    .payBtn {
      padding: 0 10px;
      // width: ;
      .svg-icon {
        font-size: 25px;
      }
    }
    .noPay {
      padding: 10px;
    }
  }
}
</style>

